import tkinter as tk

# 开始
def send():
    arr = entry.get().split(' ')
    arr = [int(item) for item in arr]
    sort_arr = shell(arr)
    result_label.config(text=','.join(map(str, sort_arr)))

# 希尔排序
def shell(arr):
    len_arr = len(arr)
    gap = len_arr // 2
    while gap > 0:
        for i in range(gap, len_arr):
            temp = arr[i]
            j = i
            while j >= gap and arr[j - gap] > temp:
                O[0] += 1
                arr[j] = arr[j - gap]
                j -= gap
            arr[j] = temp
        gap //= 2
    return arr

# 创建主窗口
root = tk.Tk()
root.title("希尔排序")

# 创建输入框
entry = tk.Entry(root)
entry.insert(0,'1 3 2 5 61 17 9')
entry.pack()

# 创建按钮
sort_button = tk.Button(root, text="希尔排序", command=send)
sort_button.pack()

# 创建结果标签
result_label = tk.Label(root, text="")
result_label.pack()

# 初始化算法复杂度计数器
O = [0]

# 运行主循环
root.mainloop()